/*
#
#  Copyright 2011 Matthew Jannace
#
#  This file is part of RoboCode BlackHoleAgent
#
#  RoboCode BlackHoleAgent is free software: you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  RoboCode BlackHoleAgent is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with RoboCode BlackHoleAgent. If not, see
#  <http://www.gnu.org/licenses/>.
#
 */
package com.jannaceltd.TeamBlackHoleBeer.Modules.Movement;

import com.jannaceltd.TeamBlackHoleBeer.Modules.Movement.MovementMethods.GravityPoint;
import com.jannaceltd.TeamBlackHoleBeer.Modules.Movement.MovementMethods.MinimumRiskMovement;
import com.jannaceltd.TeamBlackHoleBeer.BlackHole_Abstract;
import com.jannaceltd.TeamBlackHoleBeer.BlackHole_Interface;
import com.jannaceltd.TeamBlackHoleBeer.Modules.Debug.TestPoints.TestPoint;
import java.awt.geom.Point2D;
import java.util.LinkedList;

/**
 * Class that controls all Robot Moments
 * @author Matthew Jannace <mjannace@gmail.com>
 * @version 1.0
 */
public class Movement implements BlackHole_Interface {

    private BlackHole_Abstract Agent = null;
    /**
     * Object to Control Minimum Risk Movement
     */
    public MinimumRiskMovement MRMove = null;
    /**
     * The Current State of Movement
     */
    protected MovementState currentMovementState;
    /**
     * An Gravity Point Vector used for AntiGravity Debugging
     */
    protected GravityPoint GPVector[] = null;
    /**
     * The Goal Destination of the movement
     */
    protected Point2D.Double nextDestination = null;
    /**
     * The Last Goal Destination of the movement
     */
    protected Point2D.Double lastPosition = null;
    /**
     * Test Points linkedList for Minimum Risk Debugging
     */
    public LinkedList<TestPoint> TestPoints = null;

    /**
     * Creates a Movement Object
     * @param Agent
     */
    public Movement(BlackHole_Abstract Agent) {
        this.Agent = Agent;
        MRMove = new MinimumRiskMovement(Agent, this);
        currentMovementState = MovementState.Normal;
        GPVector = new GravityPoint[2];
        nextDestination = new Point2D.Double(Agent.getX(), Agent.getY());
        lastPosition = new Point2D.Double(Agent.getX(), Agent.getY());
        TestPoints = new LinkedList<TestPoint>();
    }

    /**
     * Performs the movement operation
     */
    public void doMove() {
        switch (currentMovementState) {
            case Normal:
                MRMove.doMinimumRiskMovement();
                break;
            case Evasive:
                MRMove.doEvasiveMinimumRiskMovement();
                break;
            default:
                System.out.println("No Movement System Set");
        }
    }

    /**
     * Changes the movement state Evasive
     * so the Next time doMove() is called it will perform an Evasive Movement
     */
    public void doEvasiveMove() {
        currentMovementState = MovementState.Evasive;
    }

    /**
     * Changes the movement state Normal
     * so the Next time doMove() is called it will perform a normal Movement
     */
    public void doNormalMove() {
        currentMovementState = MovementState.Normal;
    }

    /**
     * Get the Current Movement State
     * @return currentMovementState
     */
    public MovementState getCurrentMovementState() {
        return currentMovementState;
    }

    /**
     * Sets the Current Movement State
     * @param currentMovementState
     */
    public void setCurrentMovementState(MovementState currentMovementState) {
        this.currentMovementState = currentMovementState;
    }

    /**
     * Get the Gravity Point Vector
     * @param index
     * @return GPVector[index]
     */
    public GravityPoint getGPVector(int index) {
        return GPVector[index];
    }

    /**
     * Sets the Gravity Point Vector at the given index
     * @param index
     * @param GPVector 
     */
    public void setGPVector(int index, GravityPoint GPVector) {
        this.GPVector[index] = GPVector;
    }

    /**
     * Gets the next destination location
     * @return nextDestination
     */
    public Point2D.Double getNextDestination() {
        return nextDestination;
    }

    /**
     * Sets the next destination location
     * @param nextDestination
     */
    public void setNextDestination(Point2D.Double nextDestination) {
        this.nextDestination = nextDestination;
    }

    /**
     * Gets the last position location
     * @return lastPosition
     */
    public Point2D.Double getLastPosition() {
        return lastPosition;
    }

    /**
     * Sets the last position location
     * @param lastPosition 
     */
    public void setLastPosition(Point2D.Double lastPosition) {
        this.lastPosition = lastPosition;
    }

    /**
     * Gets the Test Points LinkedList
     * @return TestPoints
     */
    public LinkedList<TestPoint> getTestPoints() {
        return TestPoints;
    }
}
